/*
 * @Author: daidai
 * @Date: 2022-01-12 14:22:29
 * @LastEditors: Please set LastEditors
 * @LastEditTime: 2022-04-28 14:53:02
 * @FilePath: \web-pc\src\pages\big-screen\router\index.js
 */
import Vue from "vue";
import VueRouter from "vue-router";

Vue.use(VueRouter);

const routes = [{
  path: '/',
  redirect: '/login',
},
{
  path: '/home',
  name: 'home',
  component: () => import(/* webpackChunkName: "LSD.bighome" */ '../views/home.vue'),
  children: [
    {
      path: '/index',
      name: 'index',
      component: () => import(/* webpackChunkName: "LSD.bighome" */ '../views/indexs/index.vue'),
    },
 
  ]
},
 {
  path: '/homeClues',
  name: 'homeClues',
  component: () => import(/* webpackChunkName: "LSD.bighome" */ '../views/homeClues.vue'),
  children: [
    {
      path: '/clues',
      name: 'clues',
      component: () => import(/* webpackChunkName: "LSD.bighome" */ '../views/clues/index.vue'),
    },
  ]
},
 {
  path: '/homeAssess',
  name: 'homeAssess',
  component: () => import(/* webpackChunkName: "LSD.bighome" */ '../views/homeAssess.vue'),
  children: [
     {
      path: '/assess',
      name: 'assess',
      component: () => import(/* webpackChunkName: "LSD.bighome" */ '../views/assess/index.vue'),
    }
  ]
},
{
  path: '/login',
  name: 'login',
  component: () => import(/* webpackChunkName: "LSD.bighome" */ '../views/login.vue'),
}
];
const router = new VueRouter({
  mode: "hash",
  // base: process.env.BASE_URL,
  routes
});
router.beforeEach((to, from, next) => {
  // 如果访问的是登录界面则直接放行
  if (to.path === '/login') return next()
  //获取用户页面token信息
  let token = window.sessionStorage.getItem('token')
  
  //如果token数据为null则跳转到指定路径
  if (!token) return next("/login")
  next()
})

export default router;